package com.excilys.webservice.soap;

import javax.jws.WebParam;
import javax.jws.WebService;

import org.springframework.beans.factory.annotation.Autowired;

import com.excilys.converter.UserDTOToUserConverter;
import com.excilys.dto.UserDTO;
import com.excilys.model.User;
import com.excilys.service.UserService;

/**
 * Class that implements JAX-WS writing user WebService. 
 * Persists an user.
 * 
 * @author excilys dev : YA
 * 
 */
@WebService(endpointInterface = "com.excilys.webservice.soap.IPersistUserWebService")
public class PersistUserWebServiceImpl implements IPersistUserWebService {

	@Autowired
	UserService userService;

	@Autowired
	UserDTOToUserConverter userConverter;

	@Override
	public void persistUserDTO(@WebParam(name = "userDTOFirstName") String userDTOFirstName, @WebParam(name = "userDTOLastName") String userDTOLastName,
			@WebParam(name = "userDTOLogin") String userDTOLogin) {
		UserDTO userDTO = new UserDTO(userDTOFirstName, userDTOLastName, userDTOLogin, null);
		User user = userConverter.convert(userDTO);
		userService.persistOneUser(user);
	}

}
